﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TuongLai_Schools
{
    public partial class frmHethonggiaoduc : Form
    {
        public frmHethonggiaoduc()
        {
            InitializeComponent();
        }
        cls_DM_Hethonggiaoduc objHethonggiaoduc = new cls_DM_Hethonggiaoduc();
        private void frmHethonggiaoduc_Load(object sender, EventArgs e)
        {
            GetAll_Hethonggiaoduc();
        }
        private void GetAll_Hethonggiaoduc()
        {
            gridControl1.DataSource = objHethonggiaoduc.GetAll_Hethonggiaoduc();
        }
        private void Save_Hethonggiaoduc()
        {
            clsDM_Hethonggiaoduc objdmhtgd = new clsDM_Hethonggiaoduc();
            objdmhtgd.TenHeThongGiaoDuc = gridView1.GetFocusedRowCellValue("TenHeThongGiaoDuc").ToString();
            objdmhtgd.GhiChu = gridView1.GetFocusedRowCellValue("GhiChu").ToString();
            bool blnResult = false;
            if (ucDataButton1.DataMode == DataState.Insert)
            {
                objdmhtgd.HeThongGiaoDucID = 1;
                objdmhtgd.isChangeable = false;
                blnResult = objHethonggiaoduc.Insert(objdmhtgd);
            }
            else
            {
                objdmhtgd.HeThongGiaoDucID = (int)gridView1.GetFocusedRowCellValue("HeThongGiaoDucID");
                objdmhtgd.isChangeable = (bool)gridView1.GetFocusedRowCellValue("isChangeable");
                blnResult = objHethonggiaoduc.update(objdmhtgd);
            }

            if (blnResult)
            {
                clsCommon.SaveSuccessfully();
                ucDataButton1.DataMode = DataState.View;
                gridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.None;
                gridView1.OptionsBehavior.Editable = false;
            }
            else
            {
                clsCommon.SaveNotSuccessfully();
                return;
            }
        }

        private void ucDataButton1_SaveHandler()
        {
            Save_Hethonggiaoduc();
        }

        private void ucDataButton1_DeleteHandler()
        {
            if (clsCommon.ConfirmDeletion(gridView1.GetFocusedRowCellValue("TenHeThongGiaoDuc").ToString()) == DialogResult.No)
                return;
            objHethonggiaoduc.delete((int)gridView1.GetFocusedRowCellValue("HeThongGiaoDucID"));
            GetAll_Hethonggiaoduc();
        }

        private void ucDataButton1_InsertHandler()
        {
            gridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Top;
            gridView1.OptionsBehavior.Editable = true;
        }

        private void ucDataButton1_CancelHandler()
        {
            gridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.None;
            gridView1.OptionsBehavior.Editable = false;
            GetAll_Hethonggiaoduc();
        }

        private void ucDataButton1_EditHandler()
        {
            gridView1.OptionsBehavior.Editable = true;
        }

    }
}
